package com.clkj.sunhelp.mvp.jobdeal.jobwaittododetail.choosephotoandupdate;

import android.support.annotation.NonNull;

import com.clkj.sunhelp.common.TipStr;
import com.clkj.sunhelp.http.HttpRequest;
import com.clkj.sunhelp.http.HttpService;
import com.clkj.sunhelp.util.LogUtil;
import com.clkj.sunhelp.util.schedulers.BaseSchedulerProvider;
import com.loopj.android.http.AsyncHttpResponseHandler;

import java.io.File;
import java.util.List;

import cz.msebera.android.httpclient.Header;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by Administrator on 2017/3/31.
 */

public class ChoosePicAndUpdatePresenter implements ChoosePicAndUpdateContract.Presenter {

    @NonNull
    ChoosePicAndUpdateContract.View mView;

    @NonNull
    private final BaseSchedulerProvider mSchedulerProvider;

    @NonNull
    private final HttpService mHttpService;

    @NonNull
    private CompositeSubscription mSubscriptions;


    public ChoosePicAndUpdatePresenter(@NonNull ChoosePicAndUpdateContract.View view, @NonNull BaseSchedulerProvider mSchedulerProvider
            , @NonNull HttpService mHttpService) {
        this.mView = view;
        this.mSchedulerProvider = mSchedulerProvider;
        this.mHttpService = mHttpService;
        this.mSubscriptions = new CompositeSubscription();

        this.mView.setPresenter(this);
    }





    @Override
    public void subscribe() {

    }

    @Override
    public void unsubscribe() {
        mSubscriptions.unsubscribe();
    }


    @Override
    public void uploadFile(String processName, String processId, String projId,String userId, List<File> fileList) {
        HttpRequest.uploadFengXianControlInfo(processName,processId, projId,userId, fileList, new AsyncHttpResponseHandler() {

            @Override
            public void onProgress(long bytesWritten, long totalSize) {
                super.onProgress(bytesWritten, totalSize);


                mView.showLoading();

            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String response = new String(responseBody);
                LogUtil.e("uploadPicResponse:" + response);


                mView.dismissLoading();
                mView.onUploadPicSuccess();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                LogUtil.e("uploadPicCode:" + statusCode);


                mView.dismissLoading();
                mView.onUploadPicError(TipStr.TIP_SERVER_GET_DATA_WRONG);
            }
        });
    }







   /* @Override
    public void loginPeople(String account, String pass) {
        mView.showLoading();

        Subscription subscription = mHttpService.loginOfPeople(account,pass)
                .subscribeOn(mSchedulerProvider.computation())
                .observeOn(mSchedulerProvider.ui())
                .filter(new Func1<JsonObject, Boolean>() {
                    @Override
                    public Boolean call(JsonObject jsonObject) {
                        LogUtil.e("loginResponse:"+ jsonObject.toString());
                        if (!jsonObject.get(Constant.RESPONSE_KEY_STATUS).getAsString().equals(Constant.SUCCESS))
                        {
                            mView.dismissLoading();
                            mView.onLoginPeopleError(jsonObject.get(Constant.RESPONSE_KEY_MESSAGE).getAsString());
                        }

                        return jsonObject.get(Constant.RESPONSE_KEY_STATUS).getAsString().equals(Constant.SUCCESS);
                    }
                })
                .subscribe(new Observer<JsonObject>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        mView.dismissLoading();
                        mView.onLoginPeopleError(TipStr.TIP_SERVER_GET_DATA_WRONG);
                    }

                    @Override
                    public void onNext(JsonObject jsonObject) {



                        mView.dismissLoading();

                        if (!jsonObject.get("data").isJsonNull())
                        {

                            //List<PolicyKindItem> policyKindList = CommonUtil.formatJsonToList(jsonObject,"data",new TypeToken<List<PolicyKindItem>>(){});

                            List<UserLoginInfo> userInfoList  = CommonUtil.formatJsonToList(jsonObject,"data",new TypeToken<List<UserLoginInfo>>(){});

                            mView.dismissLoading();
                            mView.onLoginPeopleSuccess(userInfoList.get(0));
                        }else{

                            mView.dismissLoading();
                            mView.onLoginPeopleError(TipStr.TIP_SERVER_GET_DATA_WRONG);

                        }

                    }
                });
        mSubscriptions.add(subscription);
    }
*/

}


